package com.ruoyi.back.service.impl

import com.alibaba.fastjson.JSON
import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import com.ruoyi.back.domain.v2.MemberTask
import com.ruoyi.back.mapper.MemberTaskMapper
import com.ruoyi.back.service.MemberTaskService
import com.ruoyi.back.service.TaskService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

@Service
class MemberTaskServiceImpl : ServiceImpl<MemberTaskMapper, MemberTask>(), MemberTaskService {

    @Autowired
    private lateinit var taskService: TaskService

    override fun memberTaskJson(memberId: Long): String? =
        list(KtQueryWrapper(MemberTask::class.java)
            .eq(MemberTask::memberId, memberId))
            .takeIf { it.isNotEmpty() }
            ?.run {
                JSON.toJSONString(map { it.apply {
                    taskName = taskService.getById(taskId)?.name
                } })
            }
}